package Java_Test;

public class RentConpany {
    private String name; //租车公司名字
    private String addess;//公司地址
    private String tel;//公司电话
    Car[] cars = new Car[100];

    public RentConpany(String name, String addess, String tel) {
        this.name = name;
        this.addess = addess;
        this.tel = tel;
    }

    //车放入数组
    public void add(){
      Car c1=new Jiaoche("轿车","别克英朗","皖A88888",5,400);
      Car c2=new Jiaoche("轿车","吉利-宋","皖A77777",5,400);
      Car c3=new Jiaoche("轿车","吉利-宋","皖A66666",5,500);
      Car c4=new Keche("客车","金龙大客","皖A55555",16,900);
      cars[0]=c1;
      cars[1]=c2;
      cars[2]=c3;
      cars[3]=c4;
    }
    //查看车辆情况
    public void show(){
        for (int i=0;i<cars.length;i++){
            if (cars[i]!=null){
                System.out.println(cars[i]);
            }
        }
    }
    //显示车辆信息
    public void showSelect(int type){
        for (int i=0;i<cars.length;i++){
            if (cars[i]!=null&&cars[i].getType().equals(type)){
                System.out.println(cars[i]);
            }
        }
    }
    //租车
    public Car rent(String idcard,int days){
        double money;
         for (int i=0;i<cars.length;i++){
         if (cars[i].getIdcard().equals(idcard)&&cars[i].getStste()==1&&cars[i]!=null){
              money=cars[i].discount(days);
              cars[i].setStste(0);
             System.out.println("租车成功，租金是"+money);
             return cars[i];
         }
     }
     return null;

    }
    //归还汽车
    public Car returnCar(String idcard){
for (int i=0;i<cars.length;i++){
    if (cars[i].getIdcard().equals(idcard)&&cars[i]!=null&&cars[i].getStste()==0){
        cars[i].setStste(1);
        return cars[i];
    }
}
return null;
    }
    //报废
    public void dismiss(String idcard){
    for (int i=0;i<cars.length;i++){
        if (cars[i].getIdcard().equals(idcard)&&cars[i]!=null&&cars[i].getStste()==0){
            for (int j=0;j<cars.length-1;j++){
                    cars[j]=cars[j+1];
                    cars[cars.length-1]=null;
            }
        }
    }
    }
    //添加新车
    public void  newCar(Car car){
      for (int i=0;i<cars.length;i++){
          if (cars[i]==null){
              cars[i]=car;
          }
      }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddess() {
        return addess;
    }

    public void setAddess(String addess) {
        this.addess = addess;
    }

    public String getTel() {
        return tel;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }

    public Car[] getCars() {
        return cars;
    }

    public void setCars(Car[] cars) {
        this.cars = cars;
    }
}
